package PAT;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class PAT1047 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        ArrayList<String>[] lists = new ArrayList[m+1];
        for (int i = 0; i < lists.length; i++) {
            lists[i] = new ArrayList<>();
        }
        while (n-- > 0) {
            String s = scanner.next();
            int k = scanner.nextInt();
            while (k-->0){
                lists[scanner.nextInt()].add(s);
            }
        }
        int index =0;
        for (ArrayList<String> list : lists) {
            if(index==0) {
                index ++;
                continue;
            }
            System.out.printf("%d %d",index++,list.size());
            list.sort(new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    return o1.compareTo(o2);
                }
            });
            for (String s : list) {
                System.out.printf("\n%s",s);
            }
            if(index<lists.length){
                System.out.println("");
            }
        }
    }
}
